﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using HardToolApp.Model;
using HardToolApp.Tool;

namespace HardToolApp.ViewModel
{
    public class PeripheralVM:ObservableObject
    {
        public object Model { get; set; }
        public object SendModel { get; set; }
        public PeripheralVM()
        {
            Type type = GetType();
            var v = type.GetCustomAttribute<ViewModelHelper>();
            Model = Activator.CreateInstance(v.ModelType);
            SendModel = Activator.CreateInstance(v.SendType);
            WeakReferenceMessenger.Default.Register<byte[]>(this, RecData);
        }

        public virtual void RecData(object t, byte[] b)
        {
            if ((SendModel is Peripheral))
            {
                if (b[3] != (byte)(((Peripheral)SendModel).commType))
                {
                    return;
                }
                Rec(t, b);
            }
            
        }

        public virtual void Rec(object t, byte[] b)
        {

        }

        public virtual void Send(Peripheral peripheral)
        {

        }
    }
}
